import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createHtmlPlugin } from 'vite-plugin-html'
import vio from 'vio-utils'

// https://vitejs.cn/config/
export default defineConfig({
  base: '/',
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '@comp': fileURLToPath(new URL('./src/components', import.meta.url)),
    },
  },
  plugins: [
    vue(),
    createHtmlPlugin({
      minify: false,
      inject: {
        data: {
          buildTime: vio.fmt(Date.now()),
        },
      },
    }),
  ],
  
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        additionalData: `@import url('/src/assets/var.less');`,
      }
    }
  },
  
  server: {
    open: true,
    port: 3005,
    host: '0.0.0.0',
    // proxy: {
    //   '/admin': {
    //     target: 'https://xx',
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace(/^\/admin/, ''),
    //   },
    // },
  },
  build: {
    sourcemap: false,
  },
})
